<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book django项目 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Request与Response | django项目</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C04-View/View.html" />
    
    
    <link rel="prev" href="../C04-View/index.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4.1"
        data-chapter-title="Request与Response"
        data-filepath="C04-View/RequestAndResponse.md"
        data-basepath=".."
        data-revision="Sun Nov 18 2018 07:16:17 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-IntroduceToDRF/index.html">
            
                
                    <a href="../C01-IntroduceToDRF/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        引入DjangoRESTframework
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-IntroduceToDRF/SeparatedFrontendAndBackend.html">
            
                
                    <a href="../C01-IntroduceToDRF/SeparatedFrontendAndBackend.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Web应用模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-IntroduceToDRF/IntroduceToREST.html">
            
                
                    <a href="../C01-IntroduceToDRF/IntroduceToREST.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        认识RESTful
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-IntroduceToDRF/HowToDesignREST.html">
            
                
                    <a href="../C01-IntroduceToDRF/HowToDesignREST.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        RESTful设计方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html">
            
                
                    <a href="../C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        使用Django开发REST接口
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-IntroduceToDRF/CoreTaskToDevelopRESTAPI.html">
            
                
                    <a href="../C01-IntroduceToDRF/CoreTaskToDevelopRESTAPI.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        明确REST接口开发的核心任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-IntroduceToDRF/AboutDRF.html">
            
                
                    <a href="../C01-IntroduceToDRF/AboutDRF.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        DjangoRESTframework简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-DRFProject/index.html">
            
                
                    <a href="../C02-DRFProject/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        DRF工程搭建
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-DRFProject/InstallAndConfig.html">
            
                
                    <a href="../C02-DRFProject/InstallAndConfig.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        环境安装与配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-DRFProject/TheFirstDRFProgram.html">
            
                
                    <a href="../C02-DRFProject/TheFirstDRFProgram.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        见识DRF的魅力
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Serializer/index.html">
            
                
                    <a href="../C03-Serializer/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Serializer序列化器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Serializer/Declaring.html">
            
                
                    <a href="../C03-Serializer/Declaring.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        定义Serializer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Serializer/Serializing.html">
            
                
                    <a href="../C03-Serializer/Serializing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        序列化使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Serializer/Deserializing.html">
            
                
                    <a href="../C03-Serializer/Deserializing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        反序列化使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Serializer/ModelSerializer.html">
            
                
                    <a href="../C03-Serializer/ModelSerializer.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        模型类序列化器ModelSerializer
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-View/index.html">
            
                
                    <a href="../C04-View/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="4.1" data-path="C04-View/RequestAndResponse.html">
            
                
                    <a href="../C04-View/RequestAndResponse.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Request与Response
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-View/View.html">
            
                
                    <a href="../C04-View/View.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        视图概览
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-View/ViewIntroduction.html">
            
                
                    <a href="../C04-View/ViewIntroduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        视图说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-View/ViewSet.html">
            
                
                    <a href="../C04-View/ViewSet.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        视图集ViewSet
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="C04-View/Routers.html">
            
                
                    <a href="../C04-View/Routers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        路由Router
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Components/index.html">
            
                
                    <a href="../C05-Components/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        其他功能
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Components/Authentication.html">
            
                
                    <a href="../C05-Components/Authentication.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        认证
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Components/Permissions.html">
            
                
                    <a href="../C05-Components/Permissions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        权限
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Components/Throttling.html">
            
                
                    <a href="../C05-Components/Throttling.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        限流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Components/Filtering.html">
            
                
                    <a href="../C05-Components/Filtering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        过滤
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="C05-Components/Ordering.html">
            
                
                    <a href="../C05-Components/Ordering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="C05-Components/Pagination.html">
            
                
                    <a href="../C05-Components/Pagination.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="C05-Components/Exceptions.html">
            
                
                    <a href="../C05-Components/Exceptions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="C05-Components/Documents.html">
            
                
                    <a href="../C05-Components/Documents.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        自动生成接口文档
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >django项目</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="request-&#x4E0E;-response">Request &#x4E0E; Response</h1>
<h2 id="1--request">1.  Request</h2>
<p>REST framework &#x4F20;&#x5165;&#x89C6;&#x56FE;&#x7684;request&#x5BF9;&#x8C61;&#x4E0D;&#x518D;&#x662F;Django&#x9ED8;&#x8BA4;&#x7684;HttpRequest&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x662F;REST framework&#x63D0;&#x4F9B;&#x7684;&#x6269;&#x5C55;&#x4E86;HttpRequest&#x7C7B;&#x7684;<strong>Request</strong>&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>REST framework &#x63D0;&#x4F9B;&#x4E86;<strong>Parser</strong>&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x5728;&#x63A5;&#x6536;&#x5230;&#x8BF7;&#x6C42;&#x540E;&#x4F1A;&#x81EA;&#x52A8;&#x6839;&#x636E;Content-Type&#x6307;&#x660E;&#x7684;&#x8BF7;&#x6C42;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF08;&#x5982;JSON&#x3001;&#x8868;&#x5355;&#x7B49;&#xFF09;&#x5C06;&#x8BF7;&#x6C42;&#x6570;&#x636E;&#x8FDB;&#x884C;parse&#x89E3;&#x6790;&#xFF0C;&#x89E3;&#x6790;&#x4E3A;&#x7C7B;&#x5B57;&#x5178;&#x5BF9;&#x8C61;&#x4FDD;&#x5B58;&#x5230;<strong>Request</strong>&#x5BF9;&#x8C61;&#x4E2D;&#x3002;</p>
<p><strong>Request&#x5BF9;&#x8C61;&#x7684;&#x6570;&#x636E;&#x662F;&#x81EA;&#x52A8;&#x6839;&#x636E;&#x524D;&#x7AEF;&#x53D1;&#x9001;&#x6570;&#x636E;&#x7684;&#x683C;&#x5F0F;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#x4E4B;&#x540E;&#x7684;&#x7ED3;&#x679C;&#x3002;</strong></p>
<p>&#x65E0;&#x8BBA;&#x524D;&#x7AEF;&#x53D1;&#x9001;&#x7684;&#x54EA;&#x79CD;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x6211;&#x4EEC;&#x90FD;&#x53EF;&#x4EE5;&#x4EE5;&#x7EDF;&#x4E00;&#x7684;&#x65B9;&#x5F0F;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#x3002;</p>
<h3 id="&#x5E38;&#x7528;&#x5C5E;&#x6027;">&#x5E38;&#x7528;&#x5C5E;&#x6027;</h3>
<h4 id="1&#xFF09;data">1&#xFF09;.data</h4>
<p><code>request.data</code> &#x8FD4;&#x56DE;&#x89E3;&#x6790;&#x4E4B;&#x540E;&#x7684;&#x8BF7;&#x6C42;&#x4F53;&#x6570;&#x636E;&#x3002;&#x7C7B;&#x4F3C;&#x4E8E;Django&#x4E2D;&#x6807;&#x51C6;&#x7684;<code>request.POST</code>&#x548C;    <code>request.FILES</code>&#x5C5E;&#x6027;&#xFF0C;&#x4F46;&#x63D0;&#x4F9B;&#x5982;&#x4E0B;&#x7279;&#x6027;&#xFF1A;</p>
<ul>
<li>&#x5305;&#x542B;&#x4E86;&#x89E3;&#x6790;&#x4E4B;&#x540E;&#x7684;&#x6587;&#x4EF6;&#x548C;&#x975E;&#x6587;&#x4EF6;&#x6570;&#x636E;</li>
<li>&#x5305;&#x542B;&#x4E86;&#x5BF9;POST&#x3001;PUT&#x3001;PATCH&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x89E3;&#x6790;&#x540E;&#x7684;&#x6570;&#x636E;</li>
<li>&#x5229;&#x7528;&#x4E86;REST framework&#x7684;parsers&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x4E0D;&#x4EC5;&#x652F;&#x6301;&#x8868;&#x5355;&#x7C7B;&#x578B;&#x6570;&#x636E;&#xFF0C;&#x4E5F;&#x652F;&#x6301;JSON&#x6570;&#x636E;</li>
</ul>
<h4 id="2&#xFF09;queryparams">2&#xFF09;.query_params</h4>
<p><code>request.query_params</code>&#x4E0E;Django&#x6807;&#x51C6;&#x7684;<code>request.GET</code>&#x76F8;&#x540C;&#xFF0C;&#x53EA;&#x662F;&#x66F4;&#x6362;&#x4E86;&#x66F4;&#x6B63;&#x786E;&#x7684;&#x540D;&#x79F0;&#x800C;&#x5DF2;&#x3002;</p>
<h2 id="2--response">2.  Response</h2>
<p><code>rest_framework.response.Response</code></p>
<p>REST framework&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x54CD;&#x5E94;&#x7C7B;<code>Response</code>&#xFF0C;&#x4F7F;&#x7528;&#x8BE5;&#x7C7B;&#x6784;&#x9020;&#x54CD;&#x5E94;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x54CD;&#x5E94;&#x7684;&#x5177;&#x4F53;&#x6570;&#x636E;&#x5185;&#x5BB9;&#x4F1A;&#x88AB;&#x8F6C;&#x6362;&#xFF08;render&#x6E32;&#x67D3;&#xFF09;&#x6210;&#x7B26;&#x5408;&#x524D;&#x7AEF;&#x9700;&#x6C42;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<p>REST framework&#x63D0;&#x4F9B;&#x4E86;<code>Renderer</code> &#x6E32;&#x67D3;&#x5668;&#xFF0C;&#x7528;&#x6765;&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x5934;&#x4E2D;&#x7684;<code>Accept</code>&#xFF08;&#x63A5;&#x6536;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x58F0;&#x660E;&#xFF09;&#x6765;&#x81EA;&#x52A8;&#x8F6C;&#x6362;&#x54CD;&#x5E94;&#x6570;&#x636E;&#x5230;&#x5BF9;&#x5E94;&#x683C;&#x5F0F;&#x3002;&#x5982;&#x679C;&#x524D;&#x7AEF;&#x8BF7;&#x6C42;&#x4E2D;&#x672A;&#x8FDB;&#x884C;Accept&#x58F0;&#x660E;&#xFF0C;&#x5219;&#x4F1A;&#x91C7;&#x7528;&#x9ED8;&#x8BA4;&#x65B9;&#x5F0F;&#x5904;&#x7406;&#x54CD;&#x5E94;&#x6570;&#x636E;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x6765;&#x4FEE;&#x6539;&#x9ED8;&#x8BA4;&#x54CD;&#x5E94;&#x683C;&#x5F0F;&#x3002;</p>
<pre><code class="lang-python">REST_FRAMEWORK = {
    <span class="hljs-string">&apos;DEFAULT_RENDERER_CLASSES&apos;</span>: (  <span class="hljs-comment"># &#x9ED8;&#x8BA4;&#x54CD;&#x5E94;&#x6E32;&#x67D3;&#x7C7B;</span>
        <span class="hljs-string">&apos;rest_framework.renderers.JSONRenderer&apos;</span>,  <span class="hljs-comment"># json&#x6E32;&#x67D3;&#x5668;</span>
        <span class="hljs-string">&apos;rest_framework.renderers.BrowsableAPIRenderer&apos;</span>,  <span class="hljs-comment"># &#x6D4F;&#x89C8;API&#x6E32;&#x67D3;&#x5668;</span>
    )
}
</code></pre>
<h3 id="&#x6784;&#x9020;&#x65B9;&#x5F0F;">&#x6784;&#x9020;&#x65B9;&#x5F0F;</h3>
<pre><code class="lang-python">Response(data, status=<span class="hljs-keyword">None</span>, template_name=<span class="hljs-keyword">None</span>, headers=<span class="hljs-keyword">None</span>, content_type=<span class="hljs-keyword">None</span>)
</code></pre>
<p><code>data</code>&#x6570;&#x636E;&#x4E0D;&#x8981;&#x662F;render&#x5904;&#x7406;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x53EA;&#x9700;&#x4F20;&#x9012;python&#x7684;&#x5185;&#x5EFA;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x5373;&#x53EF;&#xFF0C;REST framework&#x4F1A;&#x4F7F;&#x7528;<code>renderer</code>&#x6E32;&#x67D3;&#x5668;&#x5904;&#x7406;<code>data</code>&#x3002;</p>
<p><code>data</code>&#x4E0D;&#x80FD;&#x662F;&#x590D;&#x6742;&#x7ED3;&#x6784;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5982;Django&#x7684;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x4E8E;&#x8FD9;&#x6837;&#x7684;&#x6570;&#x636E;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>Serializer</code>&#x5E8F;&#x5217;&#x5316;&#x5668;&#x5E8F;&#x5217;&#x5316;&#x5904;&#x7406;&#x540E;&#xFF08;&#x8F6C;&#x4E3A;&#x4E86;Python&#x5B57;&#x5178;&#x7C7B;&#x578B;&#xFF09;&#x518D;&#x4F20;&#x9012;&#x7ED9;<code>data</code>&#x53C2;&#x6570;&#x3002;</p>
<p>&#x53C2;&#x6570;&#x8BF4;&#x660E;&#xFF1A;</p>
<ul>
<li><code>data</code>: &#x4E3A;&#x54CD;&#x5E94;&#x51C6;&#x5907;&#x7684;&#x5E8F;&#x5217;&#x5316;&#x5904;&#x7406;&#x540E;&#x7684;&#x6570;&#x636E;&#xFF1B;</li>
<li><code>status</code>: &#x72B6;&#x6001;&#x7801;&#xFF0C;&#x9ED8;&#x8BA4;200&#xFF1B;</li>
<li><code>template_name</code>: &#x6A21;&#x677F;&#x540D;&#x79F0;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;<code>HTMLRenderer</code> &#x65F6;&#x9700;&#x6307;&#x660E;&#xFF1B;</li>
<li><code>headers</code>: &#x7528;&#x4E8E;&#x5B58;&#x653E;&#x54CD;&#x5E94;&#x5934;&#x4FE1;&#x606F;&#x7684;&#x5B57;&#x5178;&#xFF1B;</li>
<li><code>content_type</code>:  &#x54CD;&#x5E94;&#x6570;&#x636E;&#x7684;Content-Type&#xFF0C;&#x901A;&#x5E38;&#x6B64;&#x53C2;&#x6570;&#x65E0;&#x9700;&#x4F20;&#x9012;&#xFF0C;REST framework&#x4F1A;&#x6839;&#x636E;&#x524D;&#x7AEF;&#x6240;&#x9700;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x6765;&#x8BBE;&#x7F6E;&#x8BE5;&#x53C2;&#x6570;&#x3002;</li>
</ul>
<h4 id="&#x5E38;&#x7528;&#x5C5E;&#x6027;&#xFF1A;">&#x5E38;&#x7528;&#x5C5E;&#x6027;&#xFF1A;</h4>
<h5 id="1&#xFF09;data">1&#xFF09;.data</h5>
<p>&#x4F20;&#x7ED9;response&#x5BF9;&#x8C61;&#x7684;&#x5E8F;&#x5217;&#x5316;&#x540E;&#xFF0C;&#x4F46;&#x5C1A;&#x672A;render&#x5904;&#x7406;&#x7684;&#x6570;&#x636E;</p>
<h5 id="2&#xFF09;statuscode">2&#xFF09;.status_code</h5>
<p>&#x72B6;&#x6001;&#x7801;&#x7684;&#x6570;&#x5B57;</p>
<h5 id="3&#xFF09;content">3&#xFF09;.content</h5>
<p>&#x7ECF;&#x8FC7;render&#x5904;&#x7406;&#x540E;&#x7684;&#x54CD;&#x5E94;&#x6570;&#x636E;</p>
<h2 id="3-&#x72B6;&#x6001;&#x7801;">3. &#x72B6;&#x6001;&#x7801;</h2>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x8BBE;&#x7F6E;&#x72B6;&#x6001;&#x7801;&#xFF0C;REST framewrok&#x5728;<code>rest_framework.status</code>&#x6A21;&#x5757;&#x4E2D;&#x63D0;&#x4F9B;&#x4E86;&#x5E38;&#x7528;&#x72B6;&#x6001;&#x7801;&#x5E38;&#x91CF;&#x3002;</p>
<h5 id="1&#xFF09;&#x4FE1;&#x606F;&#x544A;&#x77E5;--1xx">1&#xFF09;&#x4FE1;&#x606F;&#x544A;&#x77E5; - 1xx</h5>
<pre><code class="lang-python">HTTP_100_CONTINUE
HTTP_101_SWITCHING_PROTOCOLS
</code></pre>
<h5 id="2&#xFF09;&#x6210;&#x529F;--2xx">2&#xFF09;&#x6210;&#x529F; - 2xx</h5>
<pre><code class="lang-python">HTTP_200_OK
HTTP_201_CREATED
HTTP_202_ACCEPTED
HTTP_203_NON_AUTHORITATIVE_INFORMATION
HTTP_204_NO_CONTENT
HTTP_205_RESET_CONTENT
HTTP_206_PARTIAL_CONTENT
HTTP_207_MULTI_STATUS
</code></pre>
<h5 id="3&#xFF09;&#x91CD;&#x5B9A;&#x5411;--3xx">3&#xFF09;&#x91CD;&#x5B9A;&#x5411; - 3xx</h5>
<pre><code class="lang-python">HTTP_300_MULTIPLE_CHOICES
HTTP_301_MOVED_PERMANENTLY
HTTP_302_FOUND
HTTP_303_SEE_OTHER
HTTP_304_NOT_MODIFIED
HTTP_305_USE_PROXY
HTTP_306_RESERVED
HTTP_307_TEMPORARY_REDIRECT
</code></pre>
<h5 id="4&#xFF09;&#x5BA2;&#x6237;&#x7AEF;&#x9519;&#x8BEF;--4xx">4&#xFF09;&#x5BA2;&#x6237;&#x7AEF;&#x9519;&#x8BEF; - 4xx</h5>
<pre><code class="lang-python">HTTP_400_BAD_REQUEST
HTTP_401_UNAUTHORIZED
HTTP_402_PAYMENT_REQUIRED
HTTP_403_FORBIDDEN
HTTP_404_NOT_FOUND
HTTP_405_METHOD_NOT_ALLOWED
HTTP_406_NOT_ACCEPTABLE
HTTP_407_PROXY_AUTHENTICATION_REQUIRED
HTTP_408_REQUEST_TIMEOUT
HTTP_409_CONFLICT
HTTP_410_GONE
HTTP_411_LENGTH_REQUIRED
HTTP_412_PRECONDITION_FAILED
HTTP_413_REQUEST_ENTITY_TOO_LARGE
HTTP_414_REQUEST_URI_TOO_LONG
HTTP_415_UNSUPPORTED_MEDIA_TYPE
HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE
HTTP_417_EXPECTATION_FAILED
HTTP_422_UNPROCESSABLE_ENTITY
HTTP_423_LOCKED
HTTP_424_FAILED_DEPENDENCY
HTTP_428_PRECONDITION_REQUIRED
HTTP_429_TOO_MANY_REQUESTS
HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE
HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS
</code></pre>
<h5 id="5&#xFF09;&#x670D;&#x52A1;&#x5668;&#x9519;&#x8BEF;--5xx">5&#xFF09;&#x670D;&#x52A1;&#x5668;&#x9519;&#x8BEF; - 5xx</h5>
<pre><code class="lang-python">HTTP_500_INTERNAL_SERVER_ERROR
HTTP_501_NOT_IMPLEMENTED
HTTP_502_BAD_GATEWAY
HTTP_503_SERVICE_UNAVAILABLE
HTTP_504_GATEWAY_TIMEOUT
HTTP_505_HTTP_VERSION_NOT_SUPPORTED
HTTP_507_INSUFFICIENT_STORAGE
HTTP_511_NETWORK_AUTHENTICATION_REQUIRED
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C04-View/index.html" class="navigation navigation-prev " aria-label="Previous page: 视图"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C04-View/View.html" class="navigation navigation-next " aria-label="Next page: 视图概览"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontsettings":{"family":"sans","size":2,"theme":"white"},"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book django项目 -->
</html>
